package persistencia;

import beans.Usuario;
import com.thoughtworks.xstream.XStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Everton de Oliveira & Robson Medeiros
 */
public class PersistenciaUsuario {

    public void salvar(Map<String, Usuario> usuarios, String nomeArquivo) throws IOException{
        XStream xstream = new XStream();
        xstream.toXML(usuarios, new BufferedWriter(new FileWriter(nomeArquivo)));
    }

    public Map carregar(String nomeArquivo) throws FileNotFoundException{
        XStream xstream = new XStream();
        Map<String, Usuario> usuarios = new HashMap<String, Usuario>();
        usuarios = (Map) xstream.fromXML(new BufferedReader(new FileReader(nomeArquivo)));
        return usuarios;
    }

}
